#pragma once

#include "includes.h"

#include "tools.h"
#include "socket.h"
#include "buffer.h"
#include "list.h"

int AddBuffer(CBuffer*b);
int AddSocket(CSocket*b);
int AddFile(HANDLE b);

void Init();
void CleanUp();

//Sockets
int tcpconnect(char* ip, int port, int mode);
int tcplisten(int port, int max, int mode);
int tcpaccept(int sockid, int mode);
char* tcpip(int sockid);
int tcpconnected(int sockid);
int udpconnect(int port, int mode);
int sendmessage(int sockid, char*ip, int port, int buffid);
int receivemessage(int sockid, int len, int buffid);
int peekmessage(int sockid, int len, int buffid);
int setformat(int sockid, int mode, char*sep);
int setsync(int sockid, int mode);
int closesock(int sockid);
int socklasterror(int sockid);
char* myhost();
int sockexit();
int sockstart();
char* hostip(char*host);
int getsocketid(int sockid);

//Buffers
int writebyte(unsigned char val, int buffid);
int writeshort(short val, int buffid);
int writeushort(unsigned short val, int buffid);
int writeint(int val, int buffid);
int writeuint(unsigned int val, int buffid);
int writefloat(float val, int buffid);
int writedouble(double val, int buffid);
int writechars(char*str, int buffid);
int writestring(char*str, int buffid);
unsigned char readbyte(int buffid);
short readshort(int buffid);
unsigned short readushort(int buffid);
int readint(int buffid);
unsigned int readuint(int buffid);
float readfloat(int buffid);
double readdouble(int buffid);
char* readchars(int len, int buffid);
char* readstring(int buffid);
char* readsep(char*sep, int buffid);
int getpos(int pos, int buffid);
int clearbuffer(int buffid);
int buffsize(int buffid);
int setpos(int pos, int buffid);
int bytesleft(int buffid);
int createbuffer();
int freebuffer(int buffid);
int copybuffer(int destinationid, int sourceid);
int copybuffer2(int destinationid, int start, int len, int sourceid);

//tools
char* getmacaddress();
int bufferencrypt(char*pass, int buffid);
int adler32(int buffid);
int bufferexists(int buffid);
int netconnected();